package com.gn.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gn.dao.UserDao;
import com.gn.domain.User;
import com.gn.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public boolean save(User user) {
        userDao.insert(user);
        return true;
    }

    @Override
    public User select(String account, String password) {
        LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper();
        lqw.eq(User::getAccount, account);
        if (!password.equals("")) {
            lqw.eq(User::getPassword, password);
        }
        List<User> users = userDao.selectList(lqw);
        if(users.isEmpty()) return null;
        else return users.get(0);
    }

    @Override
    public boolean update(User user) {
        userDao.updateById(user);
        return true;
    }
}
